package com.cjm.algorithm.leetcode;

import com.cjm.algorithm.TreeNode;

public class MinDepth111 {
    public static int minDepth(TreeNode root) {
        if (root == null) return 0;
        int m1 = minDepth(root.left);
        int m2 = minDepth(root.right);
        return root.left == null || root.right == null ? m1+m2+1:Math.min(m1, m2) + 1;
    }


    public static void main(String[] args) {
        TreeNode treeNode = TreeNode.generatorTreeNode(new Integer[]{3,9,20,null,null,15,7});
//        TreeNode treeNode = TreeNode.generatorTreeNode(new Integer[]{2,null,3,null,4,null,5,null,6});
        System.err.println(minDepth(treeNode));
    }
}
